home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2003 March / DPPCPRO0303.ISO / Components / Microsoft ASP / _SETUP.1 / ASPWizard.jar / asp / wizard / def / DefCollection.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-20  |  3.6 KB  |  133 lines

  1. package asp.wizard.def;
  2.  
  3. import java.util.Enumeration;
  4. import java.util.Vector;
  5.  
  6. public class DefCollection extends DefAbstract {
  7.    private Vector _elements = new Vector();
  8.  
  9.    public void addElement(DefAbstract element) {
  10.       if (element != null) {
  11.          element.setParent(this);
  12.          this._elements.addElement(element);
  13.       }
  14.  
  15.    }
  16.  
  17.    public int getElementCount() {
  18.       return this._elements.size();
  19.    }
  20.  
  21.    public Enumeration getElements() {
  22.       return this._elements.elements();
  23.    }
  24.  
  25.    public Vector getElements(Class theClass) {
  26.       Vector v = new Vector();
  27.       Enumeration e = this.getElements();
  28.  
  29.       while(e.hasMoreElements()) {
  30.          Object el = e.nextElement();
  31.          if (theClass.isInstance(el)) {
  32.             v.addElement(el);
  33.          }
  34.       }
  35.  
  36.       return v;
  37.    }
  38.  
  39.    public DefAbstract getElement(String name) {
  40.       DefAbstract el = null;
  41.       boolean found = false;
  42.       Enumeration e = this.getElements();
  43.  
  44.       while(e.hasMoreElements() && !found) {
  45.          el = (DefAbstract)e.nextElement();
  46.          if (el.getName().equals(name)) {
  47.             found = true;
  48.          }
  49.       }
  50.  
  51.       return found ? el : null;
  52.    }
  53.  
  54.    public void removeAllElements() {
  55.       DefAbstract el = null;
  56.       Enumeration e = this._elements.elements();
  57.  
  58.       while(e.hasMoreElements()) {
  59.          el = (DefAbstract)e.nextElement();
  60.          el.setParent((DefCollection)null);
  61.       }
  62.  
  63.       this._elements.removeAllElements();
  64.    }
  65.  
  66.    public void removeElement(String name, Class elclass) {
  67.       DefAbstract el = this.getElement(name);
  68.       if (el != null) {
  69.          el.setParent((DefCollection)null);
  70.          this._elements.removeElement(el);
  71.       }
  72.  
  73.    }
  74.  
  75.    public void removeElement(DefAbstract theElement) {
  76.       boolean found = false;
  77.       Enumeration e = this.getElements();
  78.  
  79.       while(e.hasMoreElements() && !found) {
  80.          DefAbstract el = (DefAbstract)e.nextElement();
  81.          if (el == theElement) {
  82.             el.setParent((DefCollection)null);
  83.             this._elements.removeElement(el);
  84.             found = true;
  85.          }
  86.       }
  87.  
  88.    }
  89.  
  90.    public void removeElement(Class theClass) {
  91.       Enumeration e = this.getElements();
  92.  
  93.       while(e.hasMoreElements()) {
  94.          Object el = e.nextElement();
  95.          String className = el.getClass().getName();
  96.          if (className == theClass.getName()) {
  97.             ((DefAbstract)el).setParent((DefCollection)null);
  98.             this._elements.removeElement(el);
  99.          }
  100.       }
  101.  
  102.    }
  103.  
  104.    public boolean hasElement(DefAbstract anElement) {
  105.       return this._elements.indexOf(anElement) != -1;
  106.    }
  107.  
  108.    public String getUniqueNameFor(DefAbstract anElement) {
  109.       if (anElement == null) {
  110.          return null;
  111.       } else {
  112.          int index = 1;
  113.          String baseName = anElement.getBaseName();
  114.          Enumeration e = this._elements.elements();
  115.  
  116.          while(e.hasMoreElements()) {
  117.             String uniqueName = baseName + Integer.toString(index);
  118.             DefAbstract currElement = (DefAbstract)e.nextElement();
  119.             if (currElement.getName().equals(uniqueName) && currElement != anElement) {
  120.                ++index;
  121.             }
  122.          }
  123.  
  124.          String uniqueName = baseName + Integer.toString(index);
  125.          return uniqueName;
  126.       }
  127.    }
  128.  
  129.    public String getBaseName() {
  130.       return "AbstractType";
  131.    }
  132. }
  133.